﻿@model SelfMadeMillionaire.Web.Infrastructure.ViewModels.Account.PortfolioDialogModel

<div class="modal-dialog">
    <div class="modal-content">
        @using (Html.BeginForm("PortfolioDialog", "Profile", FormMethod.Post, new { @class = "form-horizontal" }))
        {
		    @Html.HiddenFor(m => m.Id)
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title" id="edit-dialog-label">@(Model.Id >= 0? "Edit Watch List" : "New Watch List")</h4>
          </div>
          <div class="modal-body">		 
              @Html.ValidationSummary(true)
                
              <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
		            <td>
			            <div class="form-group">
				            @Html.LabelFor(m => m.Name, new { @class = "col-sm-3 control-label custom_label" })
				            <div class="col-sm-7">
				                @Html.TextBoxFor(m => m.Name, new { @class = "form-control", placeholder = "Watch List Name" })
					            @Html.ValidationMessageFor(m => m.Name)
				            </div>
			            </div>
		            </td>
	              </tr>
              </table>
          </div>
            
          <div class="modal-footer">
		      <div class="row">
		        <div class="col-sm-12">
			        <div class="pull-right">
				        <input type="submit" class="btn btn-default width80" value="Save" />
				        <a href="#" class="btn btn-default width80" data-dismiss="modal">Cancel</a>
			        </div>
		        </div>
	        </div>
          </div>
		  }
    </div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->

<script type="text/javascript">
	$(function () {

	    TestSession();

	    $("input[type='submit']").click(function (e) {
			e.preventDefault();

			var form = $(this).closest("form");

			if ($(form).valid()) {
				$.ajax({
					url: $(form).attr("action"),
					type: "POST",
					data: form.serialize(),
					cache: false,
					success: function (result) {
					    if (result.success) {
					        $('#userPortfolioDialog').on('hidden.bs.modal', function () {
					            $("#SelectedPortfolioId").val(result.id);
					            LoadUserPortfolios();
					        })
					        $("#userPortfolioDialog").modal('hide');

					    }
					    else {
					        $("#userPortfolioDialog").html(result);
					    }
					}
				});
			}
		});

	});
</script>


